"""
@File    :   router.py
@Time    :   2024/01/07 20:00:35
@Author  :   Qrj
@Email   :   923207736@qq.com
@description   :   路由统一注册
"""


from fastapi import FastAPI

from src.utils.auto_import import AutoImportUtil
from src.utils.path import PathUtil


def register_routers(app: FastAPI):
    """自动注册路由
    递归遍历业务代码中的每个文件夹中的router.py文件, 将其中的APIRouter对象导出并注册

    Args:
        app (FastAPI): Fastapi实例
    """
    # 获取项目根目录路径
    root_path = PathUtil.get_project_root_path()
    # 获取业务代码路径
    business_path = PathUtil.get_business_path()
    # 递归遍历并注册路由
    AutoImportUtil.auto_import_router(root_path, business_path, app)
